package com.example.ymdd.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.ymdd.myapplication.event.MangoBus;
import com.example.ymdd.myapplication.event.Subscribe;
import com.example.ymdd.myapplication.event.ThreadMode;

public class MainActivity extends AppCompatActivity {

    TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.text_view);
        MangoBus.getInstance().register(this);
    }

    public void click(View view) {
        startActivity(new Intent(this, TestActivity.class));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void subscribeEvent(MyMessage event){
        tv.setText(event.getName());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MangoBus.getInstance().unRegister(this);
    }
}
